<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>根据id制定工序物料设计单</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/bootstraptable/bootstrap-table.css" rel="stylesheet">
</head>
<body>
<div style="color: #0e9aef;margin: 20px;">您正在做的业务是：生产管理--工序物料设计--制定工序物料设计单</div>
<div class="container">
    <div id="make_process_button_div" style="text-align: right;">
        <button type="button" class="btn btn-default" id="submit_to_btn">提交</button>
        <button type="button" class="btn btn-default" id="back_btn">返回</button>
    </div>
    <div class="panel panel-default" style="margin-top: 10px;">
        <form class="form-horizontal" id="make_operation_material_form">
            <div class="page-heading">
                <div class="panel-title">
                    <h2 style="text-align: center;">工序物料设计单</h2>
                </div>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">工序单编号：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="designId" id="designId">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">设计人：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="designer" id="designer">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">产品名称：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="productName" id="productName">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">产品编号：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="productId" id="productId">
                        </div>
                    </div>
                </div>

                <!--工序设计单明细-->
                <table class="table table-bordered table-striped" data-toggle="table" id="make_process_table">
                    <thead>
                    <tr>
                        <th data-field="detailsNumber">序号</th>
                        <th data-field="procedureName">工序名称</th>
                        <th data-field="procedureId">工序编号</th>
                        <th data-field="procedureDescribe">描述</th>
                        <th data-field="labourHourAmount">工时数</th>
                        <th data-field="subtotal">工时成本小计（元）</th>
                        <th data-field="moduleSubtotal">物料成本小计</th>
                        <th data-field="devise" data-formatter="devise">设计</th>
                    </tr>
                    </thead>
                </table>
                <div class="form-group" style="margin-top: 10px;">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">工时总成本：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="costPriceSum" id="costPriceSum">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">物料总成本：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="moduleCostPriceSum"
                                   id="moduleCostPriceSum">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">设计要求：</label>
                        <div class="col-md-8">
                           <textarea class="form-control" name="procedureDescribe" id="procedureDescribe" readonly
                                     style="background-color: white;border: none;resize: none;" rows="2" cols="50">

                           </textarea>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">审核人：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="checker" id="checker">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">审核时间：</label>
                        <div class="col-md-8">
                            <input class="form-control" type="text" readonly
                                   style="background-color: white;border: none;" name="checkTime" id="checkTime">
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>


<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<script src="/js/currentTime.js"></script>

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>


<script>
    $(function () {
        //获取工序设计单id
        let id = localStorage.getItem("id")

        $.post("/manufacture/process/getIdProcess", {"id": id}, function (res) {
            $("#make_operation_material_form #designId").val(res.designId)
            $("#make_operation_material_form #designer").val(res.designer)
            $("#make_operation_material_form #productId").val(res.productId)
            $("#make_operation_material_form #productName").val(res.productName)
            $("#make_operation_material_form #costPriceSum").val(res.costPriceSum)
            $("#make_operation_material_form #moduleCostPriceSum").val(res.moduleCostPriceSum)
            $("#make_operation_material_form #procedureDescribe").val(res.procedureDescribe)
            $("#make_operation_material_form #checker").val(res.checker)
            $("#make_operation_material_form #checkTime").val(formater(res.checkTime))
        })
        $.post("/manufacture/process/getByIdProcessDetails", {"id": id}, function (res) {
            for (let i = 0; i < res.length; i++) {
                $("#make_operation_material_form #make_process_table").bootstrapTable("append", res[i])
            }
        })

        //点击返回按钮
        $("#make_process_button_div #back_btn").click(function () {
            window.location = "manufacture_unmake_operation_materialUI"
        })

        //点击提交按钮
        $("#make_process_button_div #submit_to_btn").click(function () {

            //获取工序明细表数据
            let data = $("#make_process_table").bootstrapTable("getData")

            let dto = {
                "designId": $("#make_operation_material_form #designId").val()
            }
            dto.process = data

            //判断工序物料明细是否都设计完
            //获取可用数量
            let prodId = $("#make_operation_material_form #productId").val()
            //拿到所有a标签
            let text = $("#make_process_table").find("a")
            let num = 0
            $.post("/manufacture/process/selCount", {"prodId": prodId}, function (res) {
                for (let i = 0; i < res.length; i++) {
                    num += res[i].residualAmount
                }
                for (let i = 0; i < text.length; i++) {
                    let ary = $(text[i]).html()
                    //判断是否设计
                    if (ary == "设计") {
                        alert("工序物料还未设计完，请设计完再提交")
                        return
                    }
                }
                    if (num != 0) {
                        alert("物料未用完，请用完物料")
                       return
                    }
                    //发送请求
                    $.ajax({
                        url: "/manufacture/process/processMaterialSubmission",
                        type: "post",
                        data: JSON.stringify(dto),
                        contentType: "application/json",
                        success: function (res) {
                            if (res) {
                                window.location = "manufacture_unmake_operation_materialUI"
                            }
                        }
                    })
                })
            })
        })

    function devise(value, row, index) {
        if (row.designModuleTag == "D002-0") {
            return `<a href='javascript:getById(${row.procedureId})'>设计</a>`
        }
        return `<a href='javascript:redesign(${row.procedureId})'>重新设计</a>`
    }

    //设计的方法
    function getById(sid) {
        //工序编号
        localStorage.setItem("sid", sid)
        let productId = $("#make_operation_material_form #productId").val()
        let name = $("#make_operation_material_form #productName").val()
        localStorage.setItem("productId", productId)
        localStorage.setItem("name", name)

        $.post("/manufacture/process/queryProductId", {"productId": productId}, function (res) {
            if (res == false) {
                window.location = "errorUI"
            }
            if (res == true) {
                window.location = "manufacture_formulate_process_materialsUI"
            }
        })
    }

    //重新设计的方法
    function redesign(redesignId) {
        //工序编号
        localStorage.setItem("redesignId", redesignId)
        //产品编号
        let productId = $("#make_operation_material_form #productId").val()
        //产品名称
        let name = $("#make_operation_material_form #productName").val()
        localStorage.setItem("name", name)
        localStorage.setItem("productId", productId)
        window.location = "manufacture_operation_material_redesignUI"
    }


</script>
</body>
</html>